#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int g_val = 100;

int main()
{
	pid_t id = fork();
	
	if(id == 0) //child
	{
		g_val = 200;
		printf("child pid: %d, ppid: %d, g_val: %d, &g_val: %p\n", getpid(), getppid(), g_val, &g_val);
	}
	else if(id > 0) //parent
	{
		sleep(3);
		printf("parent pid: %d, ppid: %d, g_val: %d, &g_val: %p\n", getpid(), getppid(), g_val, &g_val);
	}
	return 0;
}

/*int g_unval;
int g_val = 100;

int main(int argc, char* argv[], char* env[])
{
	printf("code addr: %p\n", main); //代码区
	char* str = "hello world";
	printf("read only addr: %p\n", str); //字符常量区
	printf("init addr: %p\n", &g_val); //初始化数据
	printf("uninit addr: %p\n", &g_unval); //未初始化数据
	int* p = (int*)malloc(10);
	printf("heap addr: %p\n", p); //堆区
	printf("stack addr: %p\n", &str); //栈区
	printf("stack addr: %p\n", &p); //栈区

	int i = 0;
	for(; argv[i]; ++i)
	{
		printf("argv[%d]: %p\n", i, argv[i]); //命令行参数
	}
	
	for(i = 0; env[i]; ++i)
	{
		printf("env[%d]: %p\n", i, env[i]); //环境变量
	}
	return 0;
}*/
